import { Component,ReactNode } from 'react';
import { Link } from 'react-router-dom'
import *as api from "../../api/index"

type Istate = {
    data:object[]
}

class Listto extends Component<any,Istate>{
    state = {
        data:[]
    }
    componentDidMount(): void {
        console.log(api);
        api.getList()
        .then((res:any)=>{
            console.log(res);
            let data = res.result
            this.setState({
                data
            })
             
        })
    }
    render(): ReactNode {
        let {data} = this.state
        // 渲染列表
        let lis = data.map((item:{[k:string]:any}) => {
           return(
                <li key={item._id}>
                    <Link to={`/detailto/${item.productId}`}>{item.productName}</Link>
                </li>
           )
        })
        return(
            <fieldset>
                <legend>列表商品</legend>
                <ul>
                    {lis}
                </ul>
            </fieldset>
        )
    }
}
export default Listto